#!/home/joshua/.pyenv/versions/2.7.13/bin/python

from datetime import datetime

from twisted.web import server, resource
from twisted.internet import reactor


class TimeResource(resource.Resource):
    isLeaf = True
    numberRequests = 0

    def render_GET(self, request):
        self.numberRequests += 1
        request.setHeader("content-type", "text/plain")
        now = datetime.now()
        timestr = now.strftime('%Y-%m-%d %H:%M:%S')
        return "#%s: %s\n" % (self.numberRequests, timestr)

reactor.listenTCP(8081, server.Site(TimeResource()))
reactor.run()
